//
//  lxShopViewController.m
//  luodansc
//
//  Created by 倫 星 on 2012/11/21.
//  Copyright (c) 2012年 方正株式会社. All rights reserved.
//

#import "lxShopViewController.h"
#import "lxLoginViewController.h"

@interface lxShopViewController ()

@end

@implementation lxShopViewController

- (id)init {
    self = [super init];
    if (nil != self) {
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"shop_car", nil) image:[UIImage imageNamed:@"tabbar-shop-car.png"] tag:2];
        self.tabBarItem = item;
        [item release];
        
        QRootElement *root = [[QRootElement alloc] init];
        root.title = NSLocalizedString(@"shop_car", nil);
        root.grouped = YES;
        root.controllerName = @"lxSetUpViewController";
        
        QSection *section = [[QSection alloc] init];
        
        NSString *str_title = NSLocalizedString(@"login", nil);
        
        QLabelElement *lb_Login = [[QLabelElement alloc] initWithTitle:str_title Value:@""];
        lb_Login.key = @"lb_Login";
        lb_Login.controllerAction = @"onLxLoginView:";
        
        QWebElement *webElement = [[QWebElement alloc] initWithTitle:NSLocalizedString(@"web_site", nil) url:web_root_mobile];
        
        [section addElement:lb_Login];
        [section addElement:webElement];
        
        [root addSection:section];
        self.root = root;
    }
    return self;
}

- (void)onLxLoginView:(QLabelElement *)labelElement {
    lxLoginViewController *lxLVC = [[[lxLoginViewController alloc] init] autorelease];
    [self.navigationController pushViewController:lxLVC animated:YES];
}

- (void)setQuickDialogTableView:(QuickDialogTableView *)aQuickDialogTableView {
    [super setQuickDialogTableView:aQuickDialogTableView];
    
    self.quickDialogTableView.backgroundView = nil;
    self.quickDialogTableView.backgroundColor = [UIColor colorWithHue:0.1174 saturation:0.7131 brightness:0.8618 alpha:1.0000];
    self.quickDialogTableView.bounces = NO;
    self.quickDialogTableView.styleProvider = self;
    
    ((QEntryElement *)[self.root elementWithKey:@"login"]).delegate = self;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.tintColor = [UIColor orangeColor];
    
    lxAPPContainer *appContainer = [lxAPPContainer sharedLxAPPContainer];
    NSString *str_title = NSLocalizedString(@"login", nil);
    [str_title retain];
    if (NO == [lxStringUtility isNil:[appContainer getUserInfoEntity].user_name]) {
        str_title = NSLocalizedString(@"user_info", nil);
    }
    
    QLabelElement *lb_Login = (QLabelElement*)[self.root elementWithKey:@"lb_Login"];
    lb_Login.title = str_title;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

-(void)cell:(UITableViewCell *)cell willAppearForElement:(QElement *)element atIndexPath:(NSIndexPath *)indexPath{
    cell.backgroundColor = [UIColor colorWithRed:0.9582 green:0.9104 blue:0.7991 alpha:1.0000];
    
    if ([element isKindOfClass:[QLabelElement class]] || [element isKindOfClass:[QWebElement class]]){
        cell.textLabel.textColor = [UIColor colorWithRed:0.6033 green:0.2323 blue:0.0000 alpha:1.0000];
    }
}

- (BOOL)QEntryShouldChangeCharactersInRangeForElement:(QEntryElement *)element andCell:(QEntryTableViewCell *)cell {
    NSLog(@"Should change characters");
    return YES;
}

- (void)QEntryEditingChangedForElement:(QEntryElement *)element andCell:(QEntryTableViewCell *)cell {
    NSLog(@"Editing changed");
}


- (void)QEntryMustReturnForElement:(QEntryElement *)element andCell:(QEntryTableViewCell *)cell {
    NSLog(@"Must return");
    
}

- (void)dealloc {
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    lxAPPContainer *appContainer = [lxAPPContainer sharedLxAPPContainer];
    NSString *str_title = NSLocalizedString(@"login", nil);
    if (NO == [lxStringUtility isNil:[appContainer getUserInfoEntity].user_name]) {
        str_title = NSLocalizedString(@"user_info", nil);
    }
    
    QLabelElement *lb_Login = (QLabelElement*)[self.root elementWithKey:@"lb_Login"];
    lb_Login.title = str_title;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
